import Index from './App.vue';
import Login from './system/login/view/login.vue';
import {TablePagingation} from '../static/common/component';
import store from "./store/store";
import VueRouter from "vue-router";
import Vue from "vue";
import routerMenu from "./routerMenu.js";
import IndexPage from './system/home/view/index.vue';
Vue.use(TablePagingation);
Vue.config.productionTip = false;
let router = new VueRouter({
    routes: [
        {
            path: '/',
            redirect: '/login',
            name: '/'
        }, {
            path: '/login',
            component: Login,
            name: 'login',
            query: {_k: randomString(7)}
        }, {
            path: '/index',
            component: IndexPage,
            name: 'index',
            query: {_k: randomString(7)},
            meta: {
                keepAlive: true // 需要被缓存
            }
        },
    ]
});


router.beforeEach((route, redirect, next) => {
    let storeObj = JSON.parse(getSeesionStorage("store"));
    if (route.path === "/index" || (route.path !== "/login" && route.path !== "/")) {
        if (router.options.routes.length === 3) {
            if (store.state.routeStore.systemRoute.length === 0 && storeObj !== null) {
                routerMenu(router, storeObj.routeStore.systemRoute);
            }
            else {
                routerMenu(router, store.state.routeStore.systemRoute);
            }
        }
    }
    next({query: route.query});
});
new Vue({
    el: "#app",
    router: router,
    store: store,
    render: h => h(Index)
});
